package com.lin.csdn.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.logging.*;

public class BaseLogger {
//打印信息
    public void infoLog(String msg){
        Logger logger=Logger.getLogger("com.utils.BaseLogger");
        ConsoleHandler consoleHandler=new ConsoleHandler();
        SimpleFormatter simpleFormatter=new SimpleFormatter();

        consoleHandler.setFormatter(simpleFormatter);
        logger.addHandler(consoleHandler);

        FileHandler fileHandler= null;
        try {
            fileHandler = new FileHandler("G:\\WIS\\Wistudio\\log\\csdnWeb.log");
            fileHandler.setFormatter(simpleFormatter);
        } catch (IOException e) {
            warningLog("无法找到日志文件，打印info信息错误");
        }
        logger.addHandler(fileHandler);
        logger.info(msg);
    }
//打印警告
    public void warningLog(String msg){
        Logger logger=Logger.getLogger("com.utils.BaseLogger");

        ConsoleHandler consoleHandler=new ConsoleHandler();
        SimpleFormatter simpleFormatter=new SimpleFormatter();
        logger.setUseParentHandlers(false);

        consoleHandler.setFormatter(simpleFormatter);
        logger.addHandler(consoleHandler);
        FileHandler fileHandler= null;
        try {
            fileHandler = new FileHandler("G:\\WIS\\Wistudio\\log\\csdnWeb.log");
            fileHandler.setFormatter(simpleFormatter);
        } catch (IOException e) {
            warningLog("无法找到日志文件，打印warning信息错误");
        }
        logger.addHandler(fileHandler);
        logger.warning(msg);
    }
//打印严重信息
    public void errorLog(String msg){
        Logger logger=Logger.getLogger("com.utils.BaseLogger");

        ConsoleHandler consoleHandler=new ConsoleHandler();
        SimpleFormatter simpleFormatter=new SimpleFormatter();

        consoleHandler.setFormatter(simpleFormatter);
        logger.addHandler(consoleHandler);
        FileHandler fileHandler= null;
        try {
            fileHandler = new FileHandler("G:\\WIS\\Wistudio\\log\\csdnWeb.log");
            fileHandler.setFormatter(simpleFormatter);
        } catch (IOException e) {
            warningLog("无法找到日志文件，打印error信息错误");
        }
        logger.addHandler(fileHandler);
        logger.severe(msg);
    }
}
